package servlets;

import java.io.IOException;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import delegate.BusinessDelegate;
import dtos.ArticuloDTO;
import entities.ConfiguracionLog;

/**
 * Servlet implementation class RealizarVenta
 */
@WebServlet("/RealizarVenta")
public class RealizarVenta extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RealizarVenta() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			String codigo = request.getParameter("codigo");
			String cantidad = String.valueOf(request.getParameter("cantidad"));
			if(codigo!=null && cantidad!=null ){
				double subtotal = BusinessDelegate.getInstancia().agregarItemAlCarrito(Integer.valueOf(codigo),Integer.valueOf(cantidad));
				String quitar= "<button type=\"button\" onclick=\"eliminarItemCarrito(" + codigo + ")\"> <img src=\"webResources/img/delete.png \" /> </button>";
				response.getWriter().write("<tr id=\"item" +codigo + "\"> <td>" + codigo + "</td><td>" + cantidad + "</td><td>" + subtotal+ "</td><td>" + quitar + "</td></tr>");
			}
		} catch (NamingException e) {
			e.printStackTrace();
		}
		
	}
}
